package cn.kooki.app.duobao.ui.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.kooki.app.duobao.R;

/**
 * Created by xiong on 2015/12/19.
 */
public class ShareDialogAdapter extends BaseAdapter {

    private final int[] imgs;
    private final String[] titles;
    private final Context context;

    public ShareDialogAdapter(Context context, String[] titles, int[] imgs) {
        this.context = context;
        this.titles = titles;
        this.imgs = imgs;
    }

    @Override
    public int getCount() {
        return titles.length;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.dialog_share_item, parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.shareDialogItemImg.setImageResource(imgs[position]);
        viewHolder.shareDialogItemName.setText(titles[position]);
        return convertView;
    }

    /**
     * This class contains all butterknife-injected Views & Layouts from layout file 'dialog_share_item.xml'
     * for easy to all layout elements.
     *
     * @author ButterKnifeZelezny, plugin for Android Studio by Avast Developers (http://github.com/avast)
     */
    static class ViewHolder {
        @Bind(R.id.share_dialog_item_img)
        ImageView shareDialogItemImg;
        @Bind(R.id.share_dialog_item_name)
        TextView shareDialogItemName;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
